package com.wechat.wechat.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.wechat.wechat.entity.OrderDetail;
import com.wechat.wechat.enums.OrderStatusEnum;
import com.wechat.wechat.enums.PayStatusEnum;
import com.wechat.wechat.utils.Date2LongSerializer;
import com.wechat.wechat.utils.EnumUtil;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 订单类，加上订单详情列表，作为数据传输
 * @author NN
 * @2020/2/20 15:47
 */
@Data
//@JsonInclude(JsonInclude.Include.NON_NULL)
public class OrderDTO {
    /*订单id*/
    private String orderId;
    /*买家姓名*/
    private String buyerName;
    /*买家电话*/
    private String buyerPhone;
    /*买家地址*/
    private String buyerAddress;
    /*买家openid*/
    private String buyerOpenid;
    /*订单金额*/
    private BigDecimal orderAmount;
    /*订单状态，默认0 新订单*/
    private Integer orderStatus = OrderStatusEnum.NEW.getCode();
    /*支付状态，默认0 等待支付*/
    private Integer payStatus = PayStatusEnum.WAIT.getCode();
    /*创建时间*/
    @JsonSerialize(using = Date2LongSerializer.class)
    private Date createTime;
    /*更新时间*/
    @JsonSerialize(using = Date2LongSerializer.class)
    private Date updateTime;
    /*订单详情列表*/
    private List<OrderDetail> orderDetailList;

    /**
     * 根据状态获取状态对应的枚举
     */
    @JsonIgnore
    public OrderStatusEnum getOrderStatusEnum()
    {
        return EnumUtil.getByCode(orderStatus,OrderStatusEnum.class);
    }
    @JsonIgnore
    public PayStatusEnum getPayStatusEnum()
    {
        return EnumUtil.getByCode(payStatus,PayStatusEnum.class);
    }

}
